package com.takeaway.service.serviceimpl;

import com.takeaway.const_.Const;
import com.takeaway.dao.daointerface.ComplaintDao;
import com.takeaway.dao.daointerface.UserDao;
import com.takeaway.dao.daolmpl.ComplaintDaoImpl;
import com.takeaway.dao.daolmpl.UserDaoImpl;
import com.takeaway.pojo.Complaint;
import com.takeaway.pojo.User;
import com.takeaway.service.serviceinterface.ComplaintService;

import java.util.ArrayList;
import java.util.List;


/**
 * @author 后台赖骏
 */

public class ComplaintServiceImpl implements ComplaintService {
    private static final ComplaintDao COMPLAINT_DAO = new ComplaintDaoImpl();
    private static final UserDao USER_DAO = new UserDaoImpl();
    @Override
    public Object[] checkComplaints() throws Exception{
        ArrayList<Complaint> complaints = COMPLAINT_DAO.selectMore(Complaint.class, new String[0]);
        List<User> users = new ArrayList<>();
        for (Complaint c: complaints) {
            String[] checkField = {Const.FIELD_ID};
            User user = USER_DAO.selectSingle(new User(), checkField, c.getUserId());
            users.add(user);
        }
        Object[] objects = new Object[2];
        objects[0] = complaints;
        objects[1] = users;
        return objects;
    }
    @Override
    public int deleteComplaint(int complaintId) throws Exception{
        String[] checkField = {Const.FIELD_ID};
        return COMPLAINT_DAO.delete(Complaint.class,checkField,complaintId);
    }

    @Override
    public int addComplaint(String text, int userId) throws Exception {

        return COMPLAINT_DAO.insert(new Complaint(userId,text));
    }
}
